import jwt
import datetime
from django.conf import settings

import logging
logger = logging.getLogger(__name__)

class JwtTool:
    def getToken(self, userid, account):
        data = {
            'userid': userid,
            'account': account,
            'exp': datetime.datetime.now() + datetime.timedelta(hours=1)
        }
        # logger.info(f"Generating token for userid: {userid}")


        return "Bearer " + jwt.encode(payload=data, key=settings.SECRET_KEY)

    def checkToken(self, token):
        return jwt.decode(token, key=settings.SECRET_KEY, algorithms="HS256")


tooljwt = JwtTool()
# print(tool.getToken(1, "admin"))
# print(tool.checkToken(
#     "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjEsImFjY291bnQiOiJhZG1pbiIsImV4cCI6MTczNDk1NTA1M30.x6LWohdqAhhvdbDNrkaBElLwgA0m1fkTBUlZV4JAPbk"))
